<?php
/**
 * Created by PhpStorm.
 * UserController: 86158
 * Date: 2020/8/1
 * Time: 14:16
 */

namespace app\models\shop;

use crmeb\basic\BaseModel;
use crmeb\traits\JwtAuthModelTrait;
use crmeb\traits\ModelTrait;

//TODO 小松新增模型
class MerchantAdmin extends BaseModel
{
    use JwtAuthModelTrait;
    use ModelTrait;

    protected $hidden = [
        'add_time', 'pwd','last_time'
    ];
    /**
     * 用户注册
     * @param $account
     * @param $password
     * @param $spread
     * @return MerchantAdmin|\think\Model
     */
    public static function register($account, $password)
    {
        if (self::be(['account' => $account])) return self::setErrorInfo('用户已存在');
        $phone = $account;
        $data['account'] = $account;
        $data['password'] = md5($password);
        $data['phone'] = $phone;
        $data['add_time'] = time();
        $data['last_time'] = time();
        $data['nickname'] = substr(md5($account . time()), 0, 12);
        $data['avatar'] = $data['headimgurl'] = sys_config('h5_avatar');
        $res = self::create($data);
        return $res;
    }
}